package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.UserBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IUserMapper extends BaseMapper<UserBean> {


    @Select("select * from t_user where u_nickName=#{userName} and u_pwd=#{pwd}")
    @ResultMap("userMap")
    UserBean login (@Param("userName") String userName,@Param("pwd") String pwd);

    @Select("select * from t_user where u_name=#{name}")
    @ResultMap("userMap")
    UserBean check(String name);



    @Insert("insert into t_user(u_name,u_nickName,u_pwd,u_level)VALUES(#{name},#{nickName},#{pwd},#{level})")
    void addUser(UserBean user);


    @Select("select * from t_user where pk_userId=#{id}")
    @ResultMap("userMap")
    UserBean checkForDel(Integer id);


    @Delete("delete  from t_user where pk_userId=#{id}")
    void delUser(Integer id);

    @Update("update t_user set u_level=#{level} where pk_userId=#{id}")
    void updateUserLevel(@Param("id") Integer id,@Param("level") String level);


    @Update("update t_user set u_pwd=#{pwd} where pk_userId=#{id}")
    void updateUserPwd(@Param("id") Integer id,@Param("pwd") String pwd);

    @Select("select * from t_user")
    @ResultMap("userMap")
    List<UserBean> findAll();

    @Select("select * from t_user where pk_userId=#{id}")
    @ResultMap("userMap")
    UserBean findById(Integer id);
}
